package com.heima.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.pojo.dto.VmTypePageDto;
import com.heima.pojo.domain.PageResult;
import com.heima.pojo.domain.VmType;
import com.heima.service.VmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/vmType")
public class VmTypeController {

    @Autowired
    private VmTypeService vmTypeService;

    @GetMapping("/search")
    public PageResult<VmType> search( VmTypePageDto pd){
        return vmTypeService.search(pd);
    }

    /**
     * 新增设备类型
     */
    @PostMapping
    public Boolean post(@RequestBody VmType vmType){
        return vmTypeService.save(vmType);
    }

    /**
     * 修改设备类型
     */
    @PutMapping("/{typeId}")
    public Boolean update(@RequestBody VmType vmType,@PathVariable Integer typeId){
        return vmTypeService.update(vmType, Wrappers.<VmType>lambdaUpdate().eq(VmType::getTypeId,typeId));
    }

    /**
     * 删除设备类型
     */
    @DeleteMapping("/{typeId}")
    public Boolean del(@PathVariable Integer typeId){
        return vmTypeService.remove(Wrappers.<VmType>lambdaQuery().eq(VmType::getTypeId,typeId));
    }

}
